package com.stottlerhenke.simbionic.editor.parser;

import java.util.ArrayList;
import java.util.List;

import com.stottlerhenke.simbionic.api.SB_VarType;


public class SB_ArrayNode extends SB_ParseNode
{
    private ArrayList _array;

    /**
     *  
     */
    public SB_ArrayNode(ArrayList array)
    {
        super(SB_VarType.kArray);
        _array = array;
    }

    public List getArray()
    {
        return _array;
    }
    
    public boolean ContainsFunction(String funcName)
    {
        int size = _array.size();
        for (int i = 0; i < size; ++i)
        {
            if (((SB_ParseNode) _array.get(i)).ContainsFunction(funcName))
                return true;
        }
        return false;
    }

    public boolean ContainsVariable(String varName)
    {
        int size = _array.size();
        for (int i = 0; i < size; ++i)
        {
            if (((SB_ParseNode) _array.get(i)).ContainsVariable(varName))
                return true;
        }
        return false;
    }

    public SB_ErrorNode GetNextError(SB_ErrorNode lastError)
    {
        SB_ErrorNode error = null;
        int size = _array.size();
        for (int i = 0; i < size; ++i)
        {
            error = ((SB_ParseNode) _array.get(i)).GetNextError(lastError);
            if (error != null)
                return error;
        }
        return null;
    }

    public boolean IsValid() 
    {
		int size = _array.size();
		for (int i = 0; i < size; ++i) 
		{
		    if (!((SB_ParseNode)_array.get(i)).IsValid())
		        return false;
		}
		return true;
	}    
    
    public String ToString()
    {
        String str = new String("{");

        int size = _array.size();
        for (int i = 0; i < size; ++i)
        {
            if (i > 0)
                str += ", ";

            str += ((SB_ParseNode) _array.get(i)).ToString();
        }

        str += "}";

        return str;
    }

}